import React     from 'react';
import Simditor  from 'simditor';
import 'simditor/styles/simditor.scss';


class RichEditor extends React.Component {
    constructor(props){
        super(props);
    }
    componentDidMount(){
        this.loadEditor();
    }
    loadEditor(){
        let elemnet   = this.refs['textarea'];
        this.simditor = new Simditor({
            textarea: $(elemnet),
            defaultValue:this.props.placeholder||'请输入内容',
            upload  :{
                url:'/manage/product/richtext_img_upload.do',
                defauleImage:'',
                fileKey:'upload_file'
            }
        })
        // 初始化事件
        this.bindEditorEvent();
    }
    // 初始化文本编辑器的事件
    bindEditorEvent(){
        this.simditor.on('valuechanged',e=>{
            // 这里用getvalue()方法 取出这个值传给父组件
            this.props.onValueChange(this.simditor.getValue());
        })
    }
    render() {
        return (
            <div className="rich-editor">
                  <textarea ref="textarea"></textarea>
            </div>
        )
    }
}

export default RichEditor